package legumes.shared.domain;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Embedded;
import javax.persistence.Id;

import com.googlecode.objectify.annotation.Entity;

@Entity
public class PlaceDelivery implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id private long id;
	private String title;
	
	@Embedded private LatLng latLng;
	@Embedded private PostalAdress postalAdress;
	
	public PlaceDelivery() {
		super();
	}

	@Override
	public String toString() {
		return title + " (" + id + ") " + latLng 
		 + " " + getPostalAdress().toString();
	}
	
	public String toHTMLString() {
		return "<h3>" + title + "</h3>" 
		+ getPostalAdress().toStringHTMLAdressPostal()
		+ "<BR/><i>" + latLng + "</i>";
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public LatLng getLatLng() {
		return latLng;
	}

	public void setLatLng(LatLng latLng) {
		this.latLng = latLng;
	}

	public PostalAdress getPostalAdress() {
		return postalAdress;
	}

	public void setPostalAddress(PostalAdress mailingAdress) {
		this.postalAdress = mailingAdress;
	}

	@Override
	public boolean equals(Object obj) {
		return (obj instanceof PlaceDelivery) 
		&& ((PlaceDelivery)obj).getId() == getId();
	}
	
	public static String [] createPlaceDeliveryNameArray(List<PlaceDelivery> pdList_){
		String [] strAr = new String[pdList_.size()];
		int i=0;
		for(PlaceDelivery s : pdList_){
			String pdName = s.getTitle();
			strAr[i] = pdName;
			i++;
		}
		return strAr;
	}
	
	public static int findPlaceDelivery(String [] placeDeliveryNameArray_, String pdNameToSelect_){
		int indexPdToSelect = -1;
		int i=0;
		for(String pdName : placeDeliveryNameArray_){
			if( pdNameToSelect_!=null && pdNameToSelect_.equalsIgnoreCase(pdName)){
				indexPdToSelect = i;
			}
			i++;
		}
		return indexPdToSelect;
	}
	
}
